package com.jdbc.connection;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author wzm
 * @create 2023-10-31 9:33
 * project_name:web2310
 */
//测试java连接mysql
public class Conn01 {
    public static void main(String[] args) throws Exception {
        //定义连接信息
        String url = "jdbc:mysql:///web2310";
        String user = "root";
        String password = "123456";



        //1.注册驱动 将驱动类加载到java虚拟机中
       Class.forName("com.mysql.cj.jdbc.Driver");

        //2.通过驱动管理器获取mysql的连接对象
   /*     Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/web2310",
                "root", "123456"

       //默认情况就是localhost:3306可以省略不写                                       );*/
        Connection conn = DriverManager.getConnection(url, user, password);
        if(conn != null){
            System.out.println("获取连接成功");
        }else{
            System.out.println("获取连接失败");
        }


    }
}
